import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

// 避免重复点击页面时报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/login",
    // name: 'Home',
    // component: Home
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    children: [
      {
        path: "services",
        component: () => import("../views/Communityservice/ServiceHome.vue"),
        meta: { key: 1 },
        // meta: { keepAlive: true },
        children: [
          {
            path: "pay-report",
            component: () =>
              import("../components/CommunityService/PayReport.vue"),
          },
          {
            path: "pay-info",
            component: () =>
              import("../components/CommunityService/PayInfo.vue"),
          },
          {
            path: "pay-list",
            component: () =>
              import("../components/CommunityService/PayList.vue"),
          },
          {
            path: "repair",
            component: () =>
              import("../components/CommunityService/Repair.vue"),
          },
          {
            path: "complaint",
            component: () =>
              import("../components/CommunityService/Complaint.vue"),
          },
        ],
      },
      {
        path: "temperature-report",
        component: () =>
          import("../views/TemperatureReport/TemperatureReport.vue"),
        children: [
          {
            path: "today-report",
            component: () =>
              import("../views/TemperatureReport/TodayReport.vue"),
          },
          {
            path: "report-list",
            component: () =>
              import("../views/TemperatureReport/TemReportList.vue"),
          },
        ],
      },
      {
        path: "news-info",
        component: () => import("../views/NewsInfo/NewsInfo.vue"),
        children: [
          {
            path: "report-news",
            component: () => import("../views/NewsInfo/ReportNews.vue"),
          },
          {
            path: "news-list",
            component: () => import("../views/NewsInfo/NewsList.vue"),
          },
        ],
      },
      {
        path: "notice-info",
        component: () => import("../views/CommunityNotice/NoticeHome.vue"),
        children: [
          {
            path: "notice-report",
            component: () =>
              import("../views/CommunityNotice/NoticeReport.vue"),
          },
          {
            path: "notice-list",
            component: () => import("../views/CommunityNotice/NoticeList.vue"),
          },
        ],
      },
      {
        path: "community-ques",
        component: () => import("../views/CommunityQues/CommunityQues.vue"),
        children: [
          {
            path: "report-ques",
            component: () => import("../views/CommunityQues/QuesReport.vue"),
          },
          {
            path: "ques-list",
            component: () => import("../views/CommunityQues/QuesList.vue"),
          },
          {
            path: "ques-detail",
            component: () => import("../views/CommunityQues/QuesDetail.vue"),
          },
        ],
      },
      {
        path: "prevention-info",
        component: () => import("../views/PreventionInfo/PreventionInfo.vue"),
        children: [
          {
            path: "prevention-list",
            component: () =>
              import("../views/PreventionInfo/preventionList.vue"),
          },
          {
            path: "prevention-report",
            component: () =>
              import("../views/PreventionInfo/preventionReport.vue"),
          },
        ],
      },
      {
        path: "people-info",
        component: () => import("../views/PeopleInfo.vue"),
        children: [
          {
            path: "people-all",
            component: () => import("@/components/PeopleInfo/PeopleAll.vue"),
          },
          {
            path: "people-pay",
            component: () => import("@/components/PeopleInfo/PeoplePay.vue"),
          },
        ],
      },
      {
        path: "apply-info",
        component: () => import("../views/InAntOutApply.vue"),
      },
      {
        path: "goout-list",
        component: () => import("../views/InAndOutList/InAndOutHListome.vue"),
        children: [
          {
            path: "go-list",
            component: () => import("../views/InAndOutList/Golist.vue"),
          },
          {
            path: "out-list",
            component: () => import("../views/InAndOutList/OutList.vue"),
          },
        ],
      },
      {
        path: "cart",
        component: () => import("../views/cart/CartHome.vue"),
        children: [
          {
            path: "cart-release",
            component: () => import("@/components/Cart/cartRelease.vue"),
          },
          {
            path: "cart-list",
            component: () => import("@/components/Cart/cartList.vue"),
          },
          {
            path: "cart-order",
            component: () => import("@/components/Cart/cartOrder.vue"),
          },
          {
            path: "cart-over",
            component: () => import("@/components/Cart/cartOverList.vue"),
          },
        ],
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
